
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
from django.conf import settings

def upload_file(Bucket, img_obj, img_name):


    config = CosConfig(Region=settings.COS_REGION, SecretId=settings.COS_SECRET_ID, SecretKey=settings.COS_SECRET_KEY, )
    # 2. 获取客户端对象
    client = CosS3Client(config)
    response = client.upload_file_from_buffer(
        # Bucket='xiechen-1302729577',
        Bucket=Bucket,
        Body=img_obj,
        Key=img_name
    )

    return 'https://{}.cos.{}.myqcloud.com/{}'.format(Bucket,settings.COS_REGION, img_name)
